package com.zbkj.service.service.monitor.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zbkj.common.model.admin.SystemAdmin;
import com.zbkj.common.model.monitor.ZfbMonitorTrafficSetMeal;
import com.zbkj.common.page.CommonPage;
import com.zbkj.common.request.PageParamRequest;
import com.zbkj.common.request.monitor.ZfbMonitorTrafficSetMealReq;
import com.zbkj.common.utils.SecurityUtil;
import com.zbkj.service.dao.monitor.ZfbMonitorTrafficSetMealMapper;
import com.zbkj.service.service.monitor.IZfbMonitorTrafficSetMealService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @ClassName: ZfbMonitorTrafficSetMealServiceImpl
 * @Description: 监控设备流量套餐
 * @Author: fanbing
 * @Date: 2024/10/27 14:34
 * @Version: V1.0
 **/

@Service
@Slf4j
public class ZfbMonitorTrafficSetMealServiceImpl extends ServiceImpl<ZfbMonitorTrafficSetMealMapper, ZfbMonitorTrafficSetMeal> implements IZfbMonitorTrafficSetMealService {
    @Autowired
    private IZfbMonitorTrafficSetMealService zfbMonitorTrafficSetMealService;

    @Autowired
    private ZfbMonitorTrafficSetMealMapper zfbMonitorTrafficSetMealMapper;

    @Override
    public boolean add(ZfbMonitorTrafficSetMealReq request) {
        SystemAdmin currentAdmin = SecurityUtil.getLoginUserVo().getUser();
        ZfbMonitorTrafficSetMeal zfbMonitorTrafficSetMeal = new ZfbMonitorTrafficSetMeal();
        BeanUtils.copyProperties(request, zfbMonitorTrafficSetMeal);
        zfbMonitorTrafficSetMeal.setCreateUser(currentAdmin.getRealName());
        zfbMonitorTrafficSetMeal.setCreateTime(LocalDateTime.now());
        zfbMonitorTrafficSetMeal.setModifyTime(LocalDateTime.now());
        zfbMonitorTrafficSetMeal.setModifyUser(zfbMonitorTrafficSetMeal.getCreateUser());
        return zfbMonitorTrafficSetMealService.save(zfbMonitorTrafficSetMeal);
    }

    @Override
    public boolean updateById(ZfbMonitorTrafficSetMealReq request) {
        SystemAdmin currentAdmin = SecurityUtil.getLoginUserVo().getUser();
        ZfbMonitorTrafficSetMeal zfbMonitorTrafficSetMeal = new ZfbMonitorTrafficSetMeal();
        BeanUtils.copyProperties(request, zfbMonitorTrafficSetMeal);
        zfbMonitorTrafficSetMeal.setModifyUser(currentAdmin.getRealName());
        zfbMonitorTrafficSetMeal.setModifyTime(LocalDateTime.now());
        return zfbMonitorTrafficSetMealService.updateById(zfbMonitorTrafficSetMeal);
    }

    @Override
    public ZfbMonitorTrafficSetMeal getById(Integer id) {
        return zfbMonitorTrafficSetMealMapper.selectById(id);
    }

    @Override
    public boolean deleteById(Integer id) {
        SystemAdmin currentAdmin = SecurityUtil.getLoginUserVo().getUser();
        ZfbMonitorTrafficSetMeal zfbMonitorTrafficSetMeal = new ZfbMonitorTrafficSetMeal();
        zfbMonitorTrafficSetMeal.setModifyUser(currentAdmin.getRealName());
        zfbMonitorTrafficSetMeal.setModifyTime(LocalDateTime.now());
        zfbMonitorTrafficSetMeal.setDeleteFlag(1);
        zfbMonitorTrafficSetMeal.setId(id);
        return zfbMonitorTrafficSetMealService.updateById(zfbMonitorTrafficSetMeal);
    }

    @Override
    public PageInfo<ZfbMonitorTrafficSetMeal> getPage(PageParamRequest pageParamRequest) {
        Page<ZfbMonitorTrafficSetMeal> page = PageHelper.startPage(pageParamRequest.getPage(), pageParamRequest.getLimit());
        LambdaQueryWrapper<ZfbMonitorTrafficSetMeal> lq = new LambdaQueryWrapper<>();
        lq.eq(ZfbMonitorTrafficSetMeal::getDeleteFlag, 0);
        List<ZfbMonitorTrafficSetMeal> setMealList = zfbMonitorTrafficSetMealService.list(lq);
        return CommonPage.copyPageInfo(page, setMealList);
    }

    @Override
    public List<ZfbMonitorTrafficSetMeal> getAll() {
        LambdaQueryWrapper<ZfbMonitorTrafficSetMeal> lq = new LambdaQueryWrapper<>();
        lq.eq(ZfbMonitorTrafficSetMeal::getDeleteFlag, 0);
        lq.orderByAsc(ZfbMonitorTrafficSetMeal::getId);
        List<ZfbMonitorTrafficSetMeal> list = zfbMonitorTrafficSetMealService.list(lq);
        return list;
    }


}
